﻿Public Class CheckBox : Inherits TextBox

	Sub New()
		MyBase.new()
		ShowCursor = False
	End Sub

	Dim Checked As Boolean
	Public Overrides Property Value() As Object
		Get
			Return If(Checked, 1, 0)
		End Get
		Set(ByVal Value As Object)
			Checked = IsNull(Value, 0) = 1
			Invalidate()
		End Set
	End Property

	Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
		e.Graphics.Clear(Themes.Current.FormColor)
		ControlPaint.DrawCheckBox(e.Graphics, Rect, If(Checked, ButtonState.Checked, ButtonState.Normal) + ButtonState.Flat)
	End Sub

	Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
		MyBase.OnMouseDown(e)
		If Rect.Contains(e.Location) Then Value = 1 - Value
	End Sub

	Dim Rect As Rectangle
	Protected Overrides Sub OnSizeChanged(e As System.EventArgs)
		MyBase.OnSizeChanged(e)
		Rect = New Rectangle(0, 0, 16, 16)
		Rect.Offset(0, (Height - Rect.Height) / 2)
	End Sub

End Class